package com.hula.onion.book.server.spider.platforms.dianrongwang;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.hula.onion.book.server.common.LoginForm;
import com.hula.onion.book.server.model.AccountInfo;
import com.hula.onion.book.server.utils.MoneyUtils;
import org.springframework.stereotype.Component;

import java.math.BigDecimal;
import java.util.HashMap;
import java.util.Map;

/**
 * Description:
 * Create Date:2018/1/17 19:49
 *
 * @author shan
 * @version 1.0
 */
@Component
public class DianRongWangSpiderHelper {

    /**
     * 组装请求参数
     *
     * @param form
     * @return
     */
    public Map<String, Object> installRequestParams(LoginForm form){

        Map<String, Object> map = new HashMap<>(3);

        map.put("identity", form.getUserName());
        map.put("password", form.getPassword());
        map.put("imgCode", form.getTicket());

        return map;

    }

    /**
     * 解析账户余额
     *
     * @param json
     * @return
     */
    public AccountInfo parseAccountBalance(String json) {

        AccountInfo accountInfo = new AccountInfo();

        JSONObject funInfo = JSON.parseObject(json)
                .getJSONObject("fun");
        Long accountInteger = funInfo.getLong("zhye");
        accountInfo.setAmount(new BigDecimal(MoneyUtils.liToYuan(accountInteger)));

        return accountInfo;
    }


}
